import asyncModule from '../../pages/async-page-example/async.module';

export default function (app) {
  function asyncPagePrealoading($q, $ocLazyLoad) {
    'ngInject';

    const deferred = $q.defer();
    require.ensure([], () => {
      $ocLazyLoad.load({
        name: asyncModule.name,
      });
      deferred.resolve(asyncModule.controller);
    });
    return deferred.promise;
  }

  function resolverProvider() {
    this.asyncPagePrealoading = asyncPagePrealoading;
    this.$get = function get() { return this; };
  }

  app.provider('resolver', resolverProvider);
}
